package 泛型.反省擦除;

import java.lang.reflect.Array;
import java.util.Arrays;

public class ArrayMaker<T> {
	private Class<T> kind;

	public ArrayMaker(Class<T> kind) {
		this.kind = kind;
	}

	T[] create(int size) {
		return (T[]) Array.newInstance(kind, size);
	}

	public static void main(String[] args) {
		// 这里我们存储的类型是 String.class 类型
		// 但是因为 泛型擦除，导致数据全部被抹掉为null
		ArrayMaker<String> stringArrayMaker = new ArrayMaker<>(String.class);
		String[] strings = stringArrayMaker.create(9);
		System.out.println(Arrays.toString(strings));
	}
}
